package com.heima.controller;

import com.heima.annotation.OperationFill;
import com.heima.dto.CourseDto;
import com.heima.result.Result;
import com.heima.service.CourseService;
import com.heima.vo.CourseVo;
import com.heima.vo.FieldListVo;
import com.heima.vo.PageResult;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "课程模块")
public class CourseController {
    @Autowired
    private CourseService courseService;

    /**
     * 查询课程列表
     * @param courseDto
     * @return
     */
    @GetMapping("/clues/course/list")
    @OperationFill
    public PageResult list(CourseDto courseDto,
                           @RequestParam(value = "params[beginCreateTime]",required = false) String begin,
                           @RequestParam(value = "params[endCreateTime]",required = false) String end){
        courseDto.setBeginTime(begin);
        courseDto.setEndTime(end);
        log.info("查询课程列表:{}",courseDto);
        return courseService.list(courseDto);
    }

    /**
     * 课程下拉框
     * @return
     */
    @GetMapping("/clues/course/listselect")
    @OperationFill
    public FieldListVo listselect(){
        log.info("课程下拉框");
        return courseService.listselect();
    }

    /**
     * 添加课程
     */
    @PostMapping("/clues/course")
    @OperationFill
    public Result addCourse(@RequestBody CourseVo courseVo){
        log.info("添加课程:{}",courseVo);
        courseService.addCourse(courseVo);
        return Result.success();
    }

    /**
     * 根据id查询课程
     */
    @GetMapping("/clues/course/{id}")
    @OperationFill
    public Result getById(@PathVariable("id") Integer id){
        log.info("根据id查询课程:{}",id);
        CourseVo courseVo = courseService.getById(id);
        return Result.success(courseVo);
    }

    /**
     * 修改课程
     */
    @PutMapping("/clues/course")
    @OperationFill
    public Result updateCourse(@RequestBody CourseVo courseVo){
        log.info("修改课程:{}",courseVo);
        courseService.updateCourse(courseVo);
        return Result.success();
    }

    /**
     * 根据id删除课程
     */
    @DeleteMapping("/clues/course/{ids}")
    @OperationFill
    public Result deleteById(@PathVariable("ids") List<Integer> ids){
        log.info("根据id删除课程:{}",ids);
        courseService.deleteById(ids);
        return Result.success();
    }
}
